home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_MacPaint / Source / shared.subproj / ProgressIndicator.m < prev    next >
Text File  |  1995-06-12  |  7KB  |  175 lines

  1. /***********************************************************************\
  2. Common class for displaying a circular progress indicator in all Convert programs
  3. Copyright (C) 1993 David John Burrowes
  4.  
  5. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.
  6.  
  7. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  8.  
  9. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  10.  
  11. The author, David John Burrowes, can be reached at:
  12.     davidjohn@kira.net.netcom.com
  13.     David John Burrowes
  14.     1926 Ivy #10
  15.     San Mateo, CA 94403-1367
  16. \***********************************************************************/
  17.  
  18. #import "ProgressIndicator.h"
  19. #import "ProgressInd.h"
  20. @implementation ProgressIndicator
  21. // #import <dpsclient/psops.h>
  22. #import <dpsclient/wraps.h>    // for PSsetgray()
  23. #import <appkit/graphics.h>    // for NX_BLACK and _WHITE
  24.  
  25. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  26. //    Method:        drawSelf::
  27. //    Parameters:    the rectangles to draw in, and a count of how many there are.
  28. //    Returns:     self
  29. //    Stores:        n/a
  30. //    Description:
  31. //        This redraws the indicator object.  Because of the simplicity of the object,
  32. //        we ignore the rects and draw the whole thing every time.
  33. //    Bugs:
  34. //        I can't remember if I must manually flush the image if we're buffered or not...
  35. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36.  
  37. - drawSelf:(const NXRect *)rects :(int)rectCount
  38. {
  39.     NXRect    theFrame;
  40.     NXRect *myFrame = &theFrame;
  41.     Real        height, width, radius, percent;
  42.     [self getBounds: myFrame];
  43.     //
  44.     //    Fill our rectangle with grey
  45.     //
  46.     PSsetgray(NX_LTGRAY);
  47.     NXRectFill(myFrame);
  48.     //
  49.     //    Now, if needed, draw the indicator.
  50.     //
  51.     if (active == YES)
  52.     {
  53.         percent =  CurrentValue / numUnits;
  54.         if (percent < 0 )    // One of the two has the wrong sign... negative progress, essentially
  55.             percent = 0;
  56.         if (percent > 1)
  57.             percent = 1;
  58.         //
  59.         //    Calculate smaller dimension use as a radius
  60.         //
  61.         height = NX_HEIGHT(myFrame);
  62.         width = NX_WIDTH(myFrame);
  63.         if (height > width)
  64.             radius = width / 2;
  65.         else
  66.             radius = height / 2;
  67.         DrawIndicator(360*percent, NX_MIDX(myFrame) ,NX_MIDY(myFrame), radius);
  68.     }
  69.     return self;
  70. }
  71.  
  72.  
  73.  
  74. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  75. //    Method:        init
  76. //    Parameters:    none
  77. //    Returns:     self
  78. //    Stores:        n/a
  79. //    Description:
  80. //        This merely initalizes the instance variables, as you would expect.
  81. //    Bugs:
  82. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  83. - init
  84. {
  85.     [super init];
  86.     
  87.     active = NO;
  88.     numUnits = 0;
  89.     CurrentValue = 0;
  90.     return self;
  91. }
  92.  
  93.  
  94. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  95. //    Method:        ActivateWithGoal
  96. //    Parameters:    A number that constitutes the 'finish line'.
  97. //    Returns:     self
  98. //    Stores:        n/a
  99. //    Description:
  100. //        This does several things.  First, it makes us active, which means we will
  101. //        now draw ourself.  Second, we set up the specified count as the number that
  102. //        constitutes our goal (That is, reaching count is 100% done).  We establish
  103. //        the current progression towards that goal as 0.  Note that the goal can be
  104. //        negative if desired.  Starting point is always 0 though.
  105. //    Bugs:
  106. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  107. - ActivateWithGoal: (Real) count
  108. {
  109.     active = YES;
  110.     numUnits = count;
  111.     CurrentValue = 0;
  112.     [window display];
  113.     return self;
  114. }
  115.  
  116.  
  117. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  118. //    Method:        Deactivate
  119. //    Parameters:    none
  120. //    Returns:     self
  121. //    Stores:        n/a
  122. //    Description:
  123. //        After clearing the internal counter and current value, and setting the active
  124. //        flag to false, this will cause this indicator to be cleared.
  125. //    Bugs:
  126. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  127. - Deactivate
  128. {
  129.     active = NO;
  130.     numUnits = 0;
  131.     CurrentValue = 0;
  132.     [window display];
  133.     return self;
  134. }
  135.  
  136.  
  137. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  138. //    Method:        IncrementBy:
  139. //    Parameters:    A value to increment our current value by
  140. //    Returns:     self
  141. //    Stores:        n/a
  142. //    Description:
  143. //        Unsurprisingly, we take our argument, and increment our current value
  144. //        by it, and then redraw.  This will cause the arc on the screen to fill a bit more
  145. //        of the circle.  (or if the units are the reverse sign of the gooal, cause it to back up)
  146. //    Bugs:
  147. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  148. - IncrementBy: (Real) units
  149. {
  150.     CurrentValue += units;
  151.     [window display];
  152.     return self;
  153. }
  154.  
  155.  
  156. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  157. //    Method:        SetTo:
  158. //    Parameters:    A new value to set the indicator to.
  159. //    Returns:     self
  160. //    Stores:        n/a
  161. //    Description:
  162. //        This discards whatever setting this object had before, and sets the current
  163. //        value to the specified setting.  The indicator is then redrawn to reflect this
  164. //        change.
  165. //    Bugs:
  166. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  167. - SetTo: (Real) units;
  168. {
  169.     CurrentValue = units;
  170.     [window display];
  171.     return self;
  172. }
  173.  
  174. @end
  175.